package com.oasistudio.ads.expert;

import com.oasistudio.ads.expert.banner.AdHistory;

import android.app.TabActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TabHost;

public class MainActivity  extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final TabHost tabHost = getTabHost();

        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("横幅广告", getResources().getDrawable(R.drawable.icon_banner_gallery))
                .setContent(new Intent(this, BannerGallery.class)));
        
        // This tab sets the intent flag so that it is recreated each time
        // the tab is clicked.
        tabHost.addTab(tabHost.newTabSpec("tab2")
                .setIndicator("展示统计",  getResources().getDrawable(R.drawable.icon_impression_stat))
                .setContent(new Intent(this, Statistics.class)
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

        tabHost.addTab(tabHost.newTabSpec("tab3")
                .setIndicator("展示清单",  getResources().getDrawable(R.drawable.icon_impression_list))
                .setContent(new Intent(this, AdHistoryGallery.class)));
        

        tabHost.addTab(tabHost.newTabSpec("tab4")
                .setIndicator("其它广告",  getResources().getDrawable(R.drawable.icon_other_type_ad))
                .setContent(new Intent(this, OthersGallery.class)));
        
        
        tabHost.addTab(tabHost.newTabSpec("tab5")
                .setIndicator("行业数据",  getResources().getDrawable(R.drawable.icon_trade_data))
                .setContent(new Intent(this, OthersStatistics.class)
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
        
        AdHistory.clearHistory();
    }
	@Override 
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		// Group ID 
		int groupId = 0; 
		// The order position of the item 
		int menuItemOrder = Menu.NONE; 
		// Create the menu item and keep a reference to it. 
		
		MenuItem menuItem = menu.add(groupId, R.integer.menu_item_first, menuItemOrder, this.getString(R.string.menu_item_union_select));
		menuItem.setIcon(this.getResources().getDrawable(R.drawable.icon_menu_select_union));
		menuItem = menu.add(groupId, R.integer.menu_item_second, menuItemOrder, this.getString(R.string.menu_item_help));
		menuItem.setIcon(this.getResources().getDrawable(R.drawable.icon_menu_help));
		return true;
	}
	
	@Override 
	public boolean onOptionsItemSelected(MenuItem item)	{
		if (item.getItemId() == R.integer.menu_item_first) {
	    	Intent intent = new Intent(this, SelectUnion.class);
	    	startActivity(intent);
		} else if(item.getItemId() == R.integer.menu_item_second)	{
			Intent intent = new Intent(this, HelpActivity.class);
			this.startActivity(intent);
		}
		return true;	
	}
	

}